July 25, 2024
Shiny is software for web app development that mitigates the need for knowledge of typical programming languages (e.g., JavaScript, HTML, and CSS) for web development.
There are a wide number of reasons why you may be interested in creating a web app with Shiny:
Additionally, web apps are a good solution for many projects since they are:
Like all web apps, Shiny can be broken down into its two major components:
The UI is what all app users see and interact with, whereas the server is what does all the work behind the scenes.
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful"),
sidebarLayout(
sidebarPanel = sidebarPanel(
sliderInput(inputId = "bins", label = "Number of bins:",
min = 1, max = 50, value = 30)
),
mainPanel = mainPanel(
plotOutput("distPlot")
)
)
)
server <- function(input, output, session) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
wait <- faithful[, 2]
bins <- seq(min(wait), max(wait), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(wait, breaks = bins, col = 'darkgray', border = 'white')
})
}
The third important component of Shiny apps is reactive expressions.
Apps can be shared using:
shinylive
)If deployed online, apps can even be embedded on separate websites
Let’s do some hands-on examples to practice building and sharing Shiny apps from the ground up